package cn.iocoder.yudao.adminserver.modules.fi.service.statistics.impl;

import cn.iocoder.yudao.adminserver.modules.fi.controller.statistics.vo.StatisticsPageReqVO;
import cn.iocoder.yudao.adminserver.modules.fi.dal.mysql.statistics.StatisticsMapper;
import cn.iocoder.yudao.adminserver.modules.fi.service.statistics.StatisticsService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;


/**
 * 项目管理 Service 实现类
 *
 * @author hickTeam
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Resource
    private StatisticsMapper Mapper;

    @Override
    public PageResult<Map> selectPage(StatisticsPageReqVO<Map> pageReqVO) {
        QueryWrapperX<Map> wrapperX = new QueryWrapperX<>();
        wrapperX.eq("p.deleted", 0)
                .inIfPresent("p.id", pageReqVO.getProjectId())
                .inIfPresent("p.project_leader_uid", pageReqVO.getProjectLeaderUid())
                .inIfPresent("p.director_uid", pageReqVO.getDirectorUid())
                .inIfPresent("p.area_manager_uid", pageReqVO.getAreaManagerUid())
                .betweenIfPresent("t.end_time", pageReqVO.getBeginEndTime(), pageReqVO.getEndEndTime())
                .betweenIfPresent("t.do_time", pageReqVO.getBeginDoTime(), pageReqVO.getEndDoTime())
                .eqIfPresent("t.maintain_id", pageReqVO.getMaintainId());
        IPage page = MyBatisUtils.buildPage(pageReqVO);
        Mapper.selectMapsPage(page, wrapperX);
        return new PageResult<>(page.getRecords(), page.getTotal());
    }
}
